<?php

namespace app\admin\controller;

use think\exception\ValidateException;
use app\model\Technical;
use app\model\Category;
use app\model\Store;

class TechnicalController extends Base
{

	function index()
	{
		$weid = weid();
		$keyword = input('post.keyword', '', 'serach_in');
		$cate_ids = input('post.cate_ids', '', 'serach_in');
		$status = input('post.status', '', 'serach_in');
		$query = Technical::where(['weid' => $weid]);

		if (!empty($this->sid)) {
			$query->where('sid', $this->sid);
		}
		if (!empty($this->ocid)) {
			$query->where('ocid', $this->ocid);
		}

		if (!empty($keyword)) {
			$query->where('name', 'like', '%' . $keyword . '%');
		}

		if (!empty($cate_ids)) {
			$query->where('cat_id',  $cate_ids);
		}

		if (!empty($status) || $status === "0") {
			$query->where(['status' => $status]);
		}

		$res = $query->order('id desc')
			->paginate(getpage())
			->toArray();

		foreach ($res['data'] as &$vo) {
			$vo['image'] = toimg($vo['image']);
			if ($vo['sid'] == 0) {
				$vo['name'] = '[自营]' . $vo['name'];
			} else {
				$vo['name'] = '[' . Store::getTitle($vo['sid']) . ']' . $vo['name'];
			}
			$vo['create_time'] = time_format($vo['create_time']);
			$vo['update_time'] = time_format($vo['update_time']);
		}
		$data['data'] = $res;
		return $this->json($data);
	}
}
